package com.manager.devicemanager.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.manager.devicemanager.common.DataSourceNameEnum;
import com.manager.devicemanager.common.Result;
import com.manager.devicemanager.entity.Testbatch;
import com.manager.devicemanager.service.ITestbatchService;
import com.manager.devicemanager.vo.PageVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wpf
 * @since 2025-05-29
 */
@RestController
@RequestMapping("/testbatch")
public class TestbatchController {
    @Autowired
    private ITestbatchService testbatchService;

    @Operation(summary = "条件查询带分页")
    @PostMapping("/page")
    public Result<IPage<Testbatch>> page(@Parameter(description = "查询条件对象") @RequestBody PageVO<Testbatch> testbatchPageVO){
        int pageNum = testbatchPageVO.getPageNum();
        int pageSize = testbatchPageVO.getPageSize();
        Testbatch testbatch = testbatchPageVO.getCondition();
        DataSourceNameEnum dataSourceNameEnum = DataSourceNameEnum.ICBOARDCONFIG;
        if ("pd".equals(testbatchPageVO.getType())){
            dataSourceNameEnum = DataSourceNameEnum.PDBOARDCONFIG;
        }
        IPage<Testbatch> testbatchPage =testbatchService.selectPage(dataSourceNameEnum.getDataSourceName()+testbatchPageVO.getDatasourceindex(),new Page<>(pageNum, pageSize),testbatch);
        return Result.success(testbatchPage);
    }

    @Operation(summary = "统计未结束的测试批次数量")
    @PostMapping("/noendcount")
    public Result<Long> noendcount(@Parameter(description = "查询条件对象") @RequestBody PageVO<Testbatch> testbatchPageVO){
        Testbatch testbatch = testbatchPageVO.getCondition();
        DataSourceNameEnum dataSourceNameEnum = DataSourceNameEnum.ICBOARDCONFIG;
        if ("pd".equals(testbatchPageVO.getType())){
            dataSourceNameEnum = DataSourceNameEnum.PDBOARDCONFIG;
        }
        Long endcount =testbatchService.noendcount(dataSourceNameEnum.getDataSourceName()+testbatchPageVO.getDatasourceindex());
        return Result.success(endcount);
    }


}
